<%@ taglib prefix="page" uri="http://com.qipay/pagelib" %>
<%@ page language="java" import="com.qipay.admin.tags.PageModel" contentType="text/html;charset=utf-8" %>
<%@ page import="java.util.Iterator" %>
<%@ page import="java.util.List" %>
<%@ page import="com.qipay.baas.model.ChannelType" %>
<%@ page import="java.math.BigDecimal" %>
<!doctype html>
<html>
<head>
    <jsp:include page="head.jsp"></jsp:include>
    <title>支付方式及费率管理</title>
    <link rel="stylesheet" href="<%= request.getAttribute("StaticHost") %>/css/dataTables.bootstrap.min.css">
</head>
<body class="devpreview hold-transition skin-blue sidebar-mini">
<div class="wrapper">
    <jsp:include page="nav.jsp"></jsp:include>
    <jsp:include page="left.jsp"></jsp:include>
    <!-- Content Wrapper. Contains page content -->
    <div class="content-wrapper">
        <!-- Main content -->
        <div id="ddd" style="display:none;position: fixed;height:330px;width:500px;margin:10% 35% 25% 20%;background: #fff;z-index: 12;">
            <div style="text-align: center;line-height: 50px;border-bottom: 1px solid #f5f5f5;font-size: 18px;">
                添加支付方式
                <a onclick="close00();" style="cursor:pointer;font-size:12px;padding:0px 20px;float:right;border-radius: 5px;">关闭</a>
            </div>
            <div style="padding:0px 20px 20px 20px;line-height: 30px;text-indent:25px;color: #000;">
                <form class="form-horizontal" action="/proxy/channelTypeSave" method="POST">
                    <div style="color: red;text-align: center;height: 30px;border: 0px solid red;">
                        <span id="tishi" style="display: none">提示：请填写完整参数</span>
                    </div>
                    <div style="padding: 10px 0;">
                        <span style="display: inline-block;width: 130px;color: #000;text-align: right">支付方式名称：</span>
                        <input id="addName" name="name" style="border: 1px solid #dcdcdc;border-radius: 3px;height: 35px;"/>
                    </div>
                    <div style="padding: 10px 0;">
                        <span style="display: inline-block;width: 130px;color: #000;text-align: right">商户费率：</span>
                        <input id="cpFeeRecharge" name="cpFeeRecharge" type="number" style="border: 1px solid #dcdcdc;border-radius: 3px;height: 35px;"/>%
                    </div>
                    <div style="padding: 10px 0;">
                        <span style="display: inline-block;width: 130px;color: #000;text-align: right">代理商费率：</span>
                        <input id="agentFeeRecharge" name="agentFeeRecharge" type="number" style="border: 1px solid #dcdcdc;border-radius: 3px;height: 35px;"/>%
                    </div>
                    <div style="text-align: center">
                        <button type="submit" onclick="return checkForm();"
                                class="btn btn-success btn-sm borderNone" >提&nbsp;交</button>
                    </div>
                </form>
            </div>
        </div>
        <div id="eee" style="display:none;position: fixed;background:#000;opacity: 0.5;height:100%;width:100%;z-index: 10;"></div>
        <script>
            function checkForm() {
                alert("进入了方法");
                var addName = $('#addName').val().trim();
                var cpFeeRecharge = $('#cpFeeRecharge').val().trim();
                var agentFeeRecharge = $('#agentFeeRecharge').val().trim();
                if(addName!=""&&cpFeeRecharge!=""&&agentFeeRecharge!=""){
                    return true;
                }
                $('#tishi').show();
                return false;
            }
            //详情
            function add(){
                $('#ddd').show();
                $('#eee').show();
            }
            //关闭
            function close00(){
                $('#ddd').hide();
                $('#eee').hide();
            }

        </script>
        <section class="content">
            <div class="row">
                <div class="col-xs-12">
                    <div class="box border" >

                        <div type="button-group">
                            <a class="btn btn-success btn-sm borderNone"
                               onclick="add();">添加支付方式</a>
                        </div>

                        <hr>
                        <!-- /.box-header -->
                        <div class="box-body">
                            <table id="example2" class="table table-bordered table-hover">
                                <thead>
                                <tr>
                                    <th>ID</th>
                                    <th>支付方式</th>
                                    <th>商户费率(%)</th>
                                    <th>代理商费率(%)</th>
                                    <th>操作</th>
                                </tr>
                                </thead>
                                <tbody>
                                <% List<ChannelType> channelTypes = (List<ChannelType>) request.getAttribute("list");
                                    if (channelTypes != null && channelTypes.size() > 0) {
                                        Iterator<ChannelType> iter = channelTypes.iterator();
                                        ChannelType user = null;
                                        while (iter.hasNext()) {
                                            user = iter.next();

                                %>
                                <tr id="user_<%=user.getId()%>">
                                    <form class="form-horizontal" action="/proxy/channelTypeSave" method="POST"></form>

                                        <td><%=user.getId()%>
                                            <input type="hidden" name="id" value="<%=user.getId()%>">
                                        </td>
                                        <td><%=user.getName()%>
                                            <input type="hidden" name="name" value="<%=user.getName()%>">
                                        </td>
                                        <td>
                                            <input style="border-radius: 3px;border: 1px solid #dcdcdc;" type="text" name="cpFeeRecharge"
                                                   value="<%=user.getCpFeeRecharge().multiply(new BigDecimal(String.valueOf("100"))).setScale(2)%>">
                                            <a name="updateCpFeeRecharge"
                                               href="javascript:;" pk="<%= user.getId()%>" pk1="<%=user.getCpFeeRecharge()%>">
                                                <button type="submit" class="btn btn-success btn-sm borderNone">修改</button>
                                            </a>
                                        </td>
                                        <td>
                                            <input style="border-radius: 3px;border: 1px solid #dcdcdc;" type="text" name="agentFeeRecharge"
                                                   value="<%=user.getAgentFeeRecharge().multiply(new BigDecimal(String.valueOf("100"))).setScale(2)%>">
                                            <a name="updateAgentFeeRecharge"
                                               href="javascript:;" pk="<%= user.getId()%>" pk1="<%=user.getAgentFeeRecharge()%>">
                                                <button type="submit" class="btn btn-success btn-sm borderNone">修改</button>
                                            </a>
                                        </td>

                                        <td>
                                            <%--<button type="submit" class="btn btn-info btn-xs">修改</button>--%>
                                            <a class="btn btn-danger btn-sm borderNone" name="lnkRemove"
                                               href="javascript:;"
                                               pk="<%= user.getId()%>">删除</a>
                                            <% if(user.getStatus()==0){%>
                                            <a class="btn btn-warning btn-sm borderNone" name="lnkOpenOrClose"
                                               href="javascript:;"
                                               pk="<%= user.getId()%>" status = "1">一键关闭</a>

                                            <% }else{%>
                                            <a class="btn btn-success btn-sm borderNone" name="lnkOpenOrClose"
                                               href="javascript:;"
                                               pk="<%= user.getId()%>" status = "0">一键打开</a>
                                            <%}%>

                                        </td>
                                </tr>
                                <%
                                    }
                                } else {
                                %>
                                <tr>
                                    <td colspan="5">no data.</td>
                                </tr>
                                <% }%>
                                </tbody>
                            </table>
                            <div class="col-sm-10">

                            </div>
                        </div>
                        <!-- /.box-body -->
                    </div>
                    <!-- /.box -->
                </div>
                <!-- /.col -->
            </div>
            <!-- /.row -->
        </section>
        <!-- /.content -->
    </div>
    <!-- /.content-wrapper -->
    <%--<jsp:include page="foot.jsp"></jsp:include>--%>
</div>
<script src="<%= request.getAttribute("StaticHost") %>/js/jquery.slimscroll.min.js"></script>
<script src="<%= request.getAttribute("StaticHost") %>/js/fastclick.js"></script>
<script src="<%= request.getAttribute("StaticHost") %>/js/adminlte.min.js"></script>
<script>

    //修改updateCpFeeRecharge
    $("[name='updateCpFeeRecharge']").click(function () {
        var pk = $(this).attr("pk");
        var pk1= $(this).parent().find('input').val()*1/100;
        if (pk > 0) {
            $.ajax({
                url: "${pageContext.request.contextPath}/ajax?n=updatecpFeeRecharge&id=" + pk+"&cpFeeRecharge="+pk1,
                type: "GET",
                async: true,//true异步 false同步
                context: this,
                timeout: 10000,
                success: function (data) {
                    if (data != null && data == "1") {
                       // $("#user_" + pk).hide(100);
                        location.reload();
                    }
                    else {
                        alert("fail:" + data);
                    }
                },
                error: function (d, s, b) {
                    alert("失败:" + b);
                }
            });
        }

    });

    //修改updateAgentFeeRecharge
    $("[name='updateAgentFeeRecharge']").click(function () {
        var pk = $(this).attr("pk");
        var pk1= $(this).parent().find('input').val()*1/100;
        if (pk > 0) {
            $.ajax({
                url: "${pageContext.request.contextPath}/ajax?n=updateagentFeeRecharge&id=" + pk+"&agentFeeRecharge="+pk1,
                type: "GET",
                async: true,//true异步 false同步
                context: this,
                timeout: 10000,
                success: function (data) {
                    if (data != null && data == "1") {
                        //$("#user_" + pk).hide(100);
                        location.reload();
                    }
                    else {
                        alert("fail:" + data);
                    }
                },
                error: function (d, s, b) {
                    alert("失败:" + b);
                }
            });
        }

    });

    //
    $(function () {
        $("[name='lnkOpenOrClose']").click(function () {
            var pk = $(this).attr("pk");
            var status = $(this).attr("status");
            var msg = status==0?"确定打开吗？":"确定关闭吗？";
            if (pk > 0) {
                if (confirm(msg)) {
                    $.ajax({
                        url: "${pageContext.request.contextPath}/ajax?n=lnkOpenOrClose&id=" + pk+ "&id2=" + status,
                        type: "GET",
                        async: true,//true异步 false同步
                        context: this,
                        timeout: 20000,
                        success: function (data) {
                            location.reload();
                        },
                        error: function (d, s, b) {
                            alert("失败:" + b);
                        }
                    });
                }
            }

        });

        $("[name='lnkRemove']").click(function () {
            var pk = $(this).attr("pk");
            if (pk > 0) {
                if (confirm("确定删除吗？")) {
                    $.ajax({
                        url: "${pageContext.request.contextPath}/ajax?n=delchannelType&id=" + pk,
                        type: "GET",
                        async: true,//true异步 false同步
                        context: this,
                        timeout: 10000,
                        success: function (data) {
                            if (data != null && data == "1") {
                                $("#user_" + pk).hide(100);
                            }
                            else {
                                alert("fail:" + data);
                            }
                        },
                        error: function (d, s, b) {
                            alert("失败:" + b);
                        }
                    });
                }
            }

        });


    });
</script>
</body>
</html>

